import {
    createStore, applyMiddleware
} from 'redux';
import thunkMiddleware from 'redux-thunk';
import {createLogger} from 'redux-logger';
import reducers from '../reducers';

let middlewares = [
    thunkMiddleware
]

// 客户端开发时加入 redux 日志
if(process.env.NODE_ENV === 'development' && __CLIENT__) {
    middlewares.push(createLogger());
}

const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore);

const configureStore = initialState =>
    createStoreWithMiddleware(reducers, initialState);

export default configureStore;